<?

require_once("layout_config.php");
require_once("include/project.php");
require_once("include/permission.php");
require_once("include/html_utils.php");

$user_id = permission_redirect_user("login.php");
$project_id = $_REQUEST['project'];

if ($_SERVER['REQUEST_METHOD'] == "POST") {
	$duration  = $_REQUEST['duration'];
	$unit      = $_REQUEST['unit'];
	$beginning = $_REQUEST['sprint_beginning'];
	$number	   = $_REQUEST['number'];

	$sprint_id = sprint_create($project_id, $number, $duration, $beginning, $unit);
	if ($sprint_id > 0) {
		header("location: projects.php?project=$project_id&sprint=$sprint_id");
	}
}

?>
<html>
<head>
<title><?=$layout_project_name?></title>
<link type="text/css" rel="stylesheet" href="themes/<?=$layout_theme; ?>/main.css" />
</head>
<body>
<?
$menu_module = "projects";
require_once("header.php");
?>
<br /><br /><br />
<table width="450" border="0" cellpadding="0" cellspacing="0" align="center">
<form method="post" action="sprint_add.php" id="sprint_add">
<input type="hidden" name="project" id="project" value="<?=$project_id?>" />
<input type="hidden" name="number" id="number" value="<?=sprint_newnumber($project_id); ?>" />
	<tr>
		<td rowspan="3" class="form_left" width="40">&nbsp;</td>
		<td height="20" class="form_title">&nbsp;New sprint</td>
	</tr>
	<tr>
		<td>
		<br>
		<table width="95%" border="0" cellpadding="1" cellspacing="1" align="center">
		<tr>
			<td align="right" height="20"><?=_("Sprint number");?>:&nbsp;</td>
			<td width="176" colspan="2"><?= sprint_newnumber($project_id); ?></td>
		</tr>
		<tr>
			<td align="right" height="20"><?=_("Duration");?>:&nbsp;</td>
			<td width="176">
				<input type="text" id="duration" name="duration" class="form_input" />
			</td>
			<td width="80">
				<select id="unit" name="unit" class="sprint_units">
				<? echo html_select_unitlist(); ?>
				</select>
			</td>
		</tr>
		<tr>
			<td align="right"><?=_("Date beginning");?>:&nbsp;</td>
			<td colspan="2">
				<input type="text" name="sprint_beginning" id="sprint_beginning" class="form_input" />
			</td>
		</tr>
		<tr>
			<td colspan="3" class="form_separator">&nbsp;</td>
		</tr>
		</table>
		<table width="99%" border="0" cellpadding="1" cellspacing="1">
			<tr>
				<td align="right" height="40">
					<a href="javascript: sprint_add.submit()">
					<img src="themes/<?=$layout_theme; ?>/images/btn_save.jpg" border="0" />
					</a>
				</td>
				<td width="65">
					<a href="projects.php">
					<img src="themes/<?=$layout_theme; ?>/images/btn_cancel.jpg" border="0" />
					</a>
				</td>
			</tr>
		</table>
		</td>
	</tr>
	<tr>
		<td class="form_left" height="4"> </td>
	</tr>
</form>
</table>
</body>
</html>
